﻿using GalaSoft.MvvmLight.Messaging;
using HuiZe.education.Common;
using HuiZe.education.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace HuiZe.education.ViewModel
{
    public class RandomAnswerShowViewModel : ViewModelBase
    {
        private string tmToken = "9d8f366b-37c0-49b3-bfd6-ddb88b94aa16";
        private int tmlog_id = 676;
        #region 属性
        /// <summary>
        /// 成功后
        /// </summary>
        public Visibility RandomAnswerSucess { get; set; }//成功显示
        /// <summary>
        /// 抽奖
        /// </summary>
        public Visibility RandomAnswerStart { get; set; }

        private string randomName;
        /// <summary>
        /// 内容
        /// </summary>
        public string RandomName
        {
            get { return randomName; }
            set { randomName = value; RaisePropertyChanged(() => RandomName); }
        }

        /// <summary>
        /// 抽奖
        /// </summary>
        public string RandomSource { get; set; }

        private AttendUserModel currUserInfo;
        public AttendUserModel CurrUserInfo { 
            get { return currUserInfo; } 
            set {
                currUserInfo = value; 
                RaisePropertyChanged(() => CurrUserInfo); 
            }
        }
        #endregion
        public RandomAnswerShowViewModel()
        {
            Init();
            Register();
        }
        public void Register()
        {
            Messenger.Default.Register<int>(this, "updateShowType", a =>
            {
                SetVisibility(a);
            });
            Messenger.Default.Register<int>(this, "updateImage", a =>
            {
                if(a== 0)
                {
                    RandomSource = "/HuiZe.education.Resource;component/Images/Toolbar/randomAnswer/1391976.png";
                }
                else
                {
                    RandomSource = "/HuiZe.education.Resource;component/Images/Toolbar/randomAnswer/1392064.png";
                }

            });
        }
        #region 方法
        public void SetVisibility(int i)
        {
            switch (i)
            {
                case 1:
                    RandomAnswerSucess = Visibility.Collapsed;
                    RandomAnswerStart = Visibility.Visible;
                    break;
                case 2:
                    RandomAnswerSucess = Visibility.Visible;
                    RandomAnswerStart = Visibility.Collapsed;
                    break;
            }
        }
        AttendClassViewModel CloudClassModel { get; set; }

        #endregion

        #region 上课抽答
        /// <summary>
        /// 上课抽答-
        /// </summary>
        public void GetclassRandom()
        {

            ReqendattendclassRandomModel model = new ReqendattendclassRandomModel()
            {
                token = tmToken,
                log_id = tmlog_id,
                grades_id = 15
            };
            string data = JsonHelper.ToJson(model);
            var result = Request<ResStudentList>("/api/student/Random", data, "上课抽答");
            if (result.Item1)
            {
                if(CurrUserInfo == null)
                    CurrUserInfo = new AttendUserModel();//当前学生

                var maa = result.Item2.data as ResStudentList;
                CurrUserInfo.UserName = result.Item2.data.name;
                CurrUserInfo.Id = result.Item2.data.id;
            }
            else
            {
                RandomName = "李先生";
            }

        }
        #endregion


        /// <summary>
        /// 抽答结果-
        /// </summary>
        public void classrandStastu()
        {

            ReqclassRandomResultModel model = new ReqclassRandomResultModel()
            {
                token = tmToken,
                log_id = tmlog_id,
                stulog_id = CurrUserInfo.Id
            };

            string data = JsonHelper.ToJson(model);
            var result = Request<ResBkBeginClassMainModel>("/api/student/randStastu", data, "抽答结果");
            if (result.Item1)
            {

            }
            else
            {
                ShowDialogView(result.Item2.msg);
            }
          

        }

        public void Init()
        {
            RandomAnswerSucess = Visibility.Collapsed;
            RandomAnswerStart = Visibility.Visible;
       
            RandomSource = "/HuiZe.education.Resource;component/Images/Toolbar/randomAnswer/1391976.png";
        }

    }
}
